package demo2;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode root = new ListNode(0 , head);
        ListNode pre = head;
        ListNode cur = head.next;
        ListNode lar = head.next.next;
        head = cur;
        while (root.next != null && root.next.next != null) {
            ListNode temp = root.next;
            root.next = root.next.next;
            temp.next = root.next.next;
            root.next.next = temp;
            root = temp;
        }
        return head;
    }}
